/**
 * Licensed under the Apache License Version 2.0.
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package net.interknit.knitter.cg.view;

import net.interknit.knitter.cg.layout.LayoutElement;
import net.interknit.knitter.cg.model.JavaType;

/**
 *
 */
public class PrimitiveTypeView extends JavaTypeView
{
	public PrimitiveTypeView(JavaType javaType)
	{
		super(javaType);
	}

	@Override
	public LayoutElement getLayoutElement()
	{
		return null;
	}

	@Override
	public String ADAPTER_DECLARATION()
	{
		if(getJavaType().getInspector().isVoidType()) return "void";
		else return getJavaType().getTypeClass().getSimpleName();
	}

	@Override
	public String ADAPTER_INSTANTIATION()
	{
		if(getJavaType().getInspector().isVoidType()) return "void";
		else return getBoxedClass(getJavaType().getTypeClass()).getSimpleName();
	}

	@Override
	public String STATE_DECLARATION()
	{
		return getJavaType().getJavaTypeDeclaration();
	}

	@Override
	public String STATE_INSTANTIATION()
	{
		return getJavaType().getJavaTypeDeclaration();
	}

	@Override
	public String VALUE_DECLARATION()
	{
		return getJavaType().getJavaTypeDeclaration();
	}

	@Override
	public String VALUE_INSTANTIATION()
	{
		return getJavaType().getJavaTypeDeclaration();
	}

	@Override
	public String UNWRAP_CLAUSE()
	{
		return "";
	}

	private static Class<?> getBoxedClass(Class<?> primitive)
	{
		if(boolean.class.equals(primitive))
			return Boolean.class;
		else if(byte.class.equals(primitive))
			return Byte.class;
		else if(char.class.equals(primitive))
			return Character.class;
		else if(short.class.equals(primitive))
			return Short.class;
		else if(int.class.equals(primitive))
			return Integer.class;
		else if(float.class.equals(primitive))
			return Float.class;
		else if(long.class.equals(primitive))
			return Long.class;
		else if(double.class.equals(primitive))
			return Double.class;
		else return primitive;
	}
}
